package com.ds.generator;

import com.ds.model.MainTemplateConfig;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

/**
 * 静态喝动态文件生成汇总
 */
public class MainGenerator {
    public static void main(String[] args) throws TemplateException, IOException {





        //静态文件生成
//        String projectPath = System.getProperty("user.dir");//获取到这个项目的根目录
//        File parentFile = new File(projectPath).getParentFile();
//        //输入路径
////        String inputPath = projectPath + File.separator + "ds-generator-demo-projects"+ File.separator+"acm-template";
//        String inputPath = new File(parentFile,"ds-generator-demo-projects/acm-template").getAbsolutePath();
//        //输出路径
//        String outputPath = projectPath;
//        StaticGenerator.copyFilesByHutool(inputPath, outputPath);
//
//        //动态文件生成
////        String dynamicprojectPath = System.getProperty("user.dir") + File.separator +"ds-generator-basic";
//        String dynamicinputPath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
//        String dynamicoutputPath = outputPath + File.separator + "acm-template/src/com/ds/acm/MainTemplate.java";

        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setAuthor("ds");
        mainTemplateConfig.setLoop(false);
        mainTemplateConfig.setOutputText("求和结果：");

        doGenerate(mainTemplateConfig);
    }


    public static void doGenerate(Object model) throws IOException, freemarker.template.TemplateException {



        String inputRootPath = "D:\\FinalProject\\ds-generatornew\\ds-generator-demo-projects\\acm-template-pro";
        String outputRootPath = "D:\\FinalProject\\ds-generatornew\\acm-template-pro";

        String inputPath;
        String outputPath;

        inputPath = new File(inputRootPath, "src/com/ds/acm/MainTemplate.java.ftl").getAbsolutePath();
        outputPath = new File(outputRootPath, "src/com/ds/acm/MainTemplate.java").getAbsolutePath();
        DynamicGenerator.doGenerate(inputPath, outputPath, model);

        inputPath = new File(inputRootPath, ".gitignore").getAbsolutePath();
        outputPath = new File(outputRootPath, ".gitignore").getAbsolutePath();
        StaticGenerator.copyFilesByHutool(inputPath, outputPath);

        inputPath = new File(inputRootPath, "README.md").getAbsolutePath();
        outputPath = new File(outputRootPath, "README.md").getAbsolutePath();
        StaticGenerator.copyFilesByHutool(inputPath, outputPath);


    }


}


